package com.laoniu.controller.sys;

import com.laoniu.annotation.OperateLog;
import com.laoniu.biz.MenuBiz;
import com.laoniu.dto.RestResult;
import com.laoniu.dto.request.MenuFormRequestDto;
import com.laoniu.dto.request.MenuListDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/menu")
public class MenuController {

    @Autowired
    private MenuBiz menuBiz;

    @PostMapping("list")
    public RestResult menuList(@RequestBody MenuListDto dto){
        return RestResult.success(menuBiz.menuList(dto));
    }

    @PostMapping("add")
    @OperateLog(bizName = "菜单管理", operateType = "新增菜单", operateDesc = "后台添加菜单")
    public RestResult add(@RequestBody MenuFormRequestDto dto){
        menuBiz.saveMenu(dto);
        return RestResult.success();
    }

    @PostMapping("update")
    @OperateLog(bizName = "菜单管理", operateType = "修改菜单", operateDesc = "后台修改菜单")
    public RestResult update(@RequestBody MenuFormRequestDto dto) {
        menuBiz.updateMenu(dto);
        return RestResult.success();
    }

    /**
     * 所有菜单树形展示
     * @return
     */
    @PostMapping("treeList")
    public RestResult treeList(){
        return RestResult.success(menuBiz.treeList());
    }

    /**
     * 用户菜单
     * @return
     */
    @PostMapping("userMenuList")
    public RestResult userMenuList(){
        return RestResult.success(menuBiz.userMenuList());
    }
}
